package a.a;

import a.c.a;
import a.c.ab;
import a.c.d;
import a.c.e;
import a.c.k;
import a.c.n;
import a.c.w;
import a.c.*;
import a.i.mb;

import java.util.ArrayList;

class o
{
  private a.c.q a;
  private int[] b;
  private int[] c;
  private int[] d;
  private int[] e;
  private int[] f;
  private int[] g;
  private int[] h;
  private int i;
  private int j;
  private int k;
  private a_ l = new a_();
  private boolean m = false;
  private a.i.a.m n;
  private boolean o = true;
  
  public String a()
  {
    return this.l.toString();
  }
  
  public void a(boolean paramBoolean)
  {
    this.m = paramBoolean;
  }
  
  public void a(a.i.a.m paramm)
  {
    this.o = false;
    this.n = paramm;
  }
  
  public int a(a.c.q paramq, k paramk1, k paramk2, k paramk3, k paramk4, n paramn, x paramx)
  {
    int i20 = m.b;
    boolean bool = m.a;
    this.l.a();
    a(paramq, paramk1, paramk2, paramk3, paramk4);
    int i2 = 0;
    int i3 = 0;
    Object localObject1 = this.a.w();
    d locald;
    int i1;
    while (((a.c.m)localObject1).e())
    {
      locald = ((a.c.m)localObject1).a();
      i1 = locald.d();
      int i4 = Math.abs(this.d[i1]);
      if (bool) {
        break label168;
      }
      if (i4 > i2) {
        i2 = i4;
      }
      if (i20 == 0)
      {
        if (this.c[i1] > i3) {
          i3 = this.c[i1];
        }
        ((a.c.m)localObject1).f();
      }
      if (bool)
      {
        if (i20 != 0) {
          break label166;
        }
        if (i20 == 0) {}
        a.c.q.n = !a.c.q.n;
      }
    }
    label166:
    if (2147483647 / this.j < i2) {
      label168:
      throw new RuntimeException("MinCostFlow Error: maxPathCost overflow!");
    }
    i2 *= this.j;
    localObject1 = new ab();
    e locale = this.a.p();
    Object localObject3 = this.a.v();
    Object localObject2;
    do
    {
      if (!((w)localObject3).e()) {
        break;
      }
      localObject2 = ((w)localObject3).d();
      if (i20 != 0) {
        break label339;
      }
      if (bool) {
        break label335;
      }
      if (localObject2 != locale)
      {
        ((ab)localObject1).add(this.a.a((e)localObject2, locale));
        ((ab)localObject1).add(this.a.a(locale, (e)localObject2));
      }
      ((w)localObject3).f();
    } while (!bool);
    this.i = this.a.m();
    this.g = new int[this.j];
    if (i20 == 0) {
      this.h = new int[this.i];
    }
    label335:
    label339:
    localObject3 = new int[this.j];
    d[] arrayOfd = new d[this.j];
    int[] arrayOfInt1 = new int[this.i];
    int[] arrayOfInt2 = new int[this.i];
    int[] arrayOfInt3 = new int[this.i];
    Object localObject4 = this.a.v();
    int i7;
    do
    {
      if (!((w)localObject4).e()) {
        break;
      }
      i7 = ((w)localObject4).d().f();
      int i5 = this.e[i7];
      int i6 = Math.abs(i5);
      if (i20 == 0)
      {
        if (i6 > i3) {
          i3 = i6;
        }
        localObject3[i7] = i5;
        ((w)localObject4).f();
      }
    } while (!bool);
    localObject4 = ((ab)localObject1).l();
    do
    {
      if (!((a.c.m)localObject4).e()) {
        break;
      }
      locald = ((a.c.m)localObject4).a();
      i1 = locald.d();
      arrayOfInt1[i1] = 2147483647;
      arrayOfInt2[i1] = i2;
      arrayOfInt3[i1] = 2147483647;
      ((a.c.m)localObject4).f();
    } while (!bool);
    localObject4 = new ab();
    a.c.m localm1 = this.a.w();
    do
    {
      if (!localm1.e()) {
        break;
      }
      locald = localm1.a();
      i1 = locald.d();
      int i9 = locald.e().f();
      int i10 = locald.f().f();
      if ((i20 == 0) && (bool)) {
        break label771;
      }
      if (arrayOfInt1[i1] != 2147483647)
      {
        arrayOfInt1[i1] = this.c[i1];
        arrayOfInt2[i1] = this.d[i1];
        int i8 = this.b[i1];
        if (i20 == 0)
        {
          if (i8 != 0)
          {
            localObject3[i9] -= i8;
            localObject3[i10] += i8;
            arrayOfInt1[i1] -= i8;
          }
          arrayOfInt3[i1] = arrayOfInt1[i1];
        }
        if (i20 != 0) {
          continue;
        }
        if (arrayOfInt2[i1] < 0)
        {
          ((ab)localObject4).add(locald);
          localObject3[i9] -= arrayOfInt1[i1];
          localObject3[i10] += arrayOfInt1[i1];
          arrayOfInt2[i1] = (-arrayOfInt2[i1]);
          this.a.e(locald);
        }
      }
      localm1.f();
    } while (!bool);
    label771:
    int i11 = 1;
    i3 = i3 * this.i / (this.j * this.j);
    if (i3 >= i11) {
      i11 *= 2;
    }
    for (;;)
    {
      if ((i20 != 0) || (!bool))
      {
        if (!bool) {
          break;
        }
        if (i20 == 0) {
          if (i11 > 0) {
            this.l.c += 1;
          }
        }
      }
    }
    label1022:
    int i18;
    label1090:
    label1102:
    label1503:
    label1529:
    while (i20 != 0)
    {
      int i14;
      do
      {
        if (bool) {
          break label1546;
        }
        localObject5 = this.a.w();
        do
        {
          if (!((a.c.m)localObject5).e()) {
            break label1102;
          }
          locald = ((a.c.m)localObject5).a();
          i1 = locald.d();
          int i12 = locald.e().f();
          i7 = locald.f().f();
          i14 = arrayOfInt2[i1] + this.g[i12] - this.g[i7];
          if (bool) {
            break;
          }
          if (i20 != 0) {
            break label1574;
          }
          if (i20 == 0)
          {
            if (arrayOfInt3[i1] >= i11)
            {
              if (i20 != 0) {
                break label1022;
              }
              if (i14 < 0)
              {
                localObject3[i7] += arrayOfInt3[i1];
                localObject3[i12] -= arrayOfInt3[i1];
                this.h[i1] = arrayOfInt1[i1];
                arrayOfInt3[i1] = 0;
                if (i20 != 0) {
                  continue;
                }
                if (!bool) {
                  break label1090;
                }
              }
            }
            if (i20 != 0) {
              continue;
            }
          }
          else if (this.h[i1] >= i11)
          {
            if (i20 != 0) {
              continue;
            }
            if (i14 > 0)
            {
              localObject3[i12] += this.h[i1];
              localObject3[i7] -= this.h[i1];
              this.h[i1] = 0;
              arrayOfInt3[i1] = arrayOfInt1[i1];
            }
          }
          ((a.c.m)localObject5).f();
        } while (!bool);
      } while (i20 != 0);
      w localw = this.a.v();
      do
      {
        do
        {
          if (!localw.e()) {
            break;
          }
          localObject5 = localw.d();
          if (bool) {
            break label1529;
          }
          i14 = ((e)localObject5).f();
          do
          {
            do
            {
              if (localObject3[i14] < i11) {
                break label1503;
              }
              this.l.d += 1;
              localObject6 = a((e)localObject5, i11, arrayOfInt2, arrayOfInt3, this.h, (int[])localObject3, arrayOfd);
              if (bool) {
                break;
              }
              if (localObject6 == null) {
                break label1503;
              }
              i17 = ((e)localObject6).f();
              i18 = localObject3[i14];
              localObject2 = localObject6;
              do
              {
                int i19;
                do
                {
                  if (localObject2 == localObject5) {
                    break;
                  }
                  locald = arrayOfd[localObject2.f()];
                  i1 = locald.d();
                  if (localObject2 == locald.f())
                  {
                    i19 = arrayOfInt3[i1];
                    localObject2 = locald.e();
                    if (i20 != 0) {
                      continue;
                    }
                    if (!bool) {}
                  }
                  else
                  {
                    i19 = this.h[i1];
                    localObject2 = locald.f();
                  }
                } while (i19 >= i18);
                i18 = i19;
                if (i20 != 0) {
                  break label1335;
                }
                if ((i20 == 0) && (bool)) {
                  break label1357;
                }
              } while ((i20 == 0) && (!bool));
              do
              {
                if ((i20 != 0) || (i18 > -localObject3[i17])) {
                  i18 = -localObject3[i17];
                }
                localObject2 = localObject6;
                do
                {
                  do
                  {
                    if (localObject2 == localObject5) {
                      break label1473;
                    }
                    locald = arrayOfd[localObject2.f()];
                    i1 = locald.d();
                    if (bool) {
                      break;
                    }
                    if (localObject2 != locald.f()) {
                      break label1439;
                    }
                    this.h[i1] += i18;
                    arrayOfInt3[i1] -= i18;
                    localObject2 = locald.e();
                    if (i20 != 0) {
                      break label1470;
                    }
                  } while (!bool);
                  this.h[i1] -= i18;
                  arrayOfInt3[i1] += i18;
                  localObject2 = locald.f();
                } while (!bool);
                localObject3[i14] -= i18;
                localObject3[i17] += i18;
              } while (i20 != 0);
            } while (!bool);
            localw.f();
          } while (i20 != 0);
        } while (!bool);
      } while (i20 != 0);
      i11 /= 2;
      if (!bool) {
        break;
      }
    }
    label1335:
    label1357:
    Object localObject5 = ((ab)localObject4).l();
    label1439:
    label1470:
    label1473:
    do
    {
      if (!((a.c.m)localObject5).e()) {
        break;
      }
      locald = ((a.c.m)localObject5).a();
      if (bool) {
        break label1621;
      }
      i1 = locald.d();
      this.h[i1] = (arrayOfInt1[i1] - this.h[i1]);
      this.a.e(locald);
      ((a.c.m)localObject5).f();
    } while (!bool);
    label1546:
    label1574:
    label1621:
    int i13 = 1;
    a.c.m localm2 = ((ab)localObject1).l();
    do
    {
      do
      {
        if (!localm2.e()) {
          break;
        }
        locald = localm2.a();
        if (bool) {
          break label1701;
        }
        if (this.h[locald.d()] != 0) {
          i13 = 0;
        }
        localm2.f();
      } while (!bool);
    } while (i20 != 0);
    localm2 = ((ab)localObject1).l();
    label1701:
    do
    {
      if (!localm2.e()) {
        break;
      }
      locald = localm2.a();
      this.a.a(locald);
      localm2.f();
      if (i20 != 0) {
        break label1770;
      }
      if (bool) {
        break label1769;
      }
    } while (!bool);
    if ((i20 == 0) && (i20 == 0)) {
      if (i13 == 0) {
        throw new RuntimeException("MinCostFlow Error: no feasible flow found!");
      }
    }
    label1769:
    label1770:
    int i15 = 0;
    Object localObject6 = this.a.w();
    do
    {
      if (!((a.c.m)localObject6).e()) {
        break;
      }
      locald = ((a.c.m)localObject6).a();
      i1 = locald.d();
      this.h[i1] += this.b[i1];
      if (i20 == 0)
      {
        if (bool) {
          break label1884;
        }
        i15 += this.h[i1] * this.d[i1];
        paramn.a(locald, this.h[i1]);
        ((a.c.m)localObject6).f();
      }
    } while (!bool);
    label1884:
    int i16 = 2147483647;
    int i17 = 0;
    do
    {
      if (i17 >= this.j) {
        break;
      }
      if ((i20 == 0) && (bool)) {
        break label2028;
      }
      if (this.g[i17] < i16) {
        i16 = this.g[i17];
      }
      i17++;
    } while (!bool);
    if (i20 == 0)
    {
      Object localObject7;
      if (paramx != null)
      {
        localObject7 = this.a.v();
        do
        {
          if (!((w)localObject7).e()) {
            break;
          }
          localObject2 = ((w)localObject7).d();
          paramx.a(localObject2, this.g[localObject2.f()] - i16);
          ((w)localObject7).f();
          if ((i20 == 0) && (bool)) {
            break label2105;
          }
        } while (!bool);
      }
      if (i20 != 0) {
        break label2105;
      }
      if (this.m)
      {
        label2028:
        localObject7 = new int[this.j];
        i18 = 0;
        do
        {
          if (i18 >= this.j) {
            break;
          }
          if (bool) {
            break label2107;
          }
          if (localObject7[i18] == 0)
          {
            if (i20 != 0) {
              continue;
            }
            if (!a(i18, (int[])localObject7)) {
              throw new RuntimeException("MinCostFlow check Error: found negative cost cycle!");
            }
          }
          i18++;
        } while (!bool);
      }
    }
    this.l.c();
    label2105:
    label2107:
    if (i20 != 0) {
      a.c.q.o = !a.c.q.o;
    }
    return i15;
  }
  
  public int a(a.c.q paramq, k paramk1, k paramk2, k paramk3, n paramn, x paramx)
  {
    n localn = paramq.C();
    return a(paramq, localn, paramk1, paramk2, paramk3, paramn, paramx);
  }
  
  public int a(a.c.q paramq, e parame1, e parame2, k paramk1, k paramk2, n paramn, x paramx)
  {
    j localj = new j();
    int i1 = localj.a(paramq, parame1, parame2, paramk1, paramn);
    x localx = paramq.B();
    localx.a(parame1, i1);
    localx.a(parame2, -i1);
    return a(paramq, paramk1, paramk2, localx, paramn, paramx);
  }
  
  private void a(a.c.q paramq, k paramk1, k paramk2, k paramk3, k paramk4)
  {
    int i4 = m.b;
    boolean bool = m.a;
    this.a = paramq;
    this.i = this.a.m();
    this.j = this.a.k();
    this.b = new int[this.i];
    this.c = new int[this.i];
    this.d = new int[this.i];
    this.e = new int[this.j];
    this.f = new int[this.j];
    if (i4 == 0) {
      if (this.o) {
        this.n = new a.i.a.q(this.a);
      }
    }
    int i2 = 0;
    this.k = 1;
    Object localObject = this.a.v();
    do
    {
      if (!((w)localObject).e()) {
        break;
      }
      e locale = ((w)localObject).d();
      int i1 = locale.f();
      this.e[i1] = paramk4.getInt(locale);
      i2 += this.e[i1];
      if (bool) {
        break label235;
      }
      if (this.e[i1] > 0) {
        this.k += this.e[i1];
      }
      ((w)localObject).f();
    } while (!bool);
    if ((i4 == 0) && (i2 != 0)) {
      label235:
      System.err.println("Warning: supply constraint broken!");
    }
    a.c.m localm = this.a.w();
    label383:
    do
    {
      if (!localm.e()) {
        break;
      }
      localObject = localm.a();
      int i3 = ((d)localObject).d();
      this.d[i3] = paramk3.getInt(localObject);
      if (i4 == 0)
      {
        if (paramk1 != null) {
          this.b[i3] = paramk1.getInt(localObject);
        }
        this.c[i3] = paramk2.getInt(localObject);
      }
      if ((i4 != 0) || (this.b[i3] >= 0))
      {
        if (i4 != 0) {
          break label383;
        }
        if (this.c[i3] >= 0) {}
      }
      else
      {
        throw new a("found negative capacity");
      }
      if (i4 == 0)
      {
        if (this.b[i3] > this.c[i3]) {
          throw new a("found lCap > uCap");
        }
        if (i4 != 0) {}
      }
      else
      {
        if (this.c[i3] == 2147483647)
        {
          this.c[i3] = this.k;
          if (i4 != 0) {
            continue;
          }
          if (this.b[i3] == 2147483647) {
            throw new a("found infinite lCap");
          }
        }
        localm.f();
      }
    } while (!bool);
  }
  
  private e a(e parame, int paramInt, int[] paramArrayOfInt1, int[] paramArrayOfInt2, int[] paramArrayOfInt3, int[] paramArrayOfInt4, d[] paramArrayOfd)
  {
    int i8 = m.b;
    boolean bool = m.a;
    this.n.d();
    int i1 = 0;
    if (i1 < this.j) {}
    e locale3;
    ArrayList localArrayList;
    do
    {
      this.f[i1] = 2147483647;
      i1++;
      if (!bool) {
        break;
      }
      locale3 = null;
      localArrayList = new ArrayList(200);
      this.f[parame.f()] = 0;
    } while (i8 != 0);
    this.n.a(parame, 0);
    int i6;
    label201:
    int i3;
    label308:
    label317:
    label336:
    label480:
    label489:
    label503:
    label504:
    while (!this.n.a())
    {
      this.l.e += 1;
      e locale1 = this.n.c();
      int i2 = locale1.f();
      localArrayList.add(locale1);
      if (paramArrayOfInt4[i2] <= -paramInt)
      {
        locale3 = locale1;
      }
      else
      {
        i6 = this.f[i2] + this.g[i2];
        d locald = locale1.h();
        int i4;
        e locale2;
        int i5;
        do
        {
          do
          {
            if (locald == null) {
              break label336;
            }
            i4 = locald.d();
            if (bool) {
              break;
            }
            if (paramArrayOfInt2[i4] >= paramInt)
            {
              locale2 = locald.f();
              i3 = locale2.f();
              i5 = i6 - this.g[i3] + paramArrayOfInt1[i4];
              if (i8 != 0) {
                continue;
              }
              if (i5 < this.f[i3])
              {
                if (i8 == 0) {
                  if (this.f[i3] == 2147483647)
                  {
                    this.n.a(locale2, i5);
                    if (i8 != 0) {
                      break label317;
                    }
                    if (!bool) {
                      break label308;
                    }
                  }
                }
                this.n.b(locale2, i5);
                this.f[i3] = i5;
                paramArrayOfd[i3] = locald;
              }
            }
            locald = locald.i();
          } while (!bool);
        } while (i8 != 0);
        locald = locale1.i();
        for (;;)
        {
          if (locald == null) {
            break label504;
          }
          i4 = locald.d();
          if (i8 != 0) {
            break label201;
          }
          if (bool) {
            break;
          }
          if (paramArrayOfInt3[i4] >= paramInt)
          {
            locale2 = locald.e();
            i3 = locale2.f();
            i5 = i6 - this.g[i3] - paramArrayOfInt1[i4];
            if (i8 != 0) {
              break label503;
            }
            if (i5 < this.f[i3])
            {
              if (i8 == 0) {
                if (this.f[i3] == 2147483647)
                {
                  this.n.a(locale2, i5);
                  if (i8 != 0) {
                    break label489;
                  }
                  if (!bool) {
                    break label480;
                  }
                }
              }
              this.n.b(locale2, i5);
              this.f[i3] = i5;
              paramArrayOfd[i3] = locald;
            }
          }
          locald = locald.j();
        }
      }
    }
    if (locale3 != null)
    {
      i6 = this.f[locale3.f()];
      int i7 = 0;
      do
      {
        if (i7 >= localArrayList.size()) {
          break;
        }
        if (bool) {
          break label586;
        }
        i3 = ((e)localArrayList.get(i7)).f();
        this.g[i3] += this.f[i3] - i6;
        i7++;
      } while (!bool);
    }
    label586:
    return locale3;
  }
  
  private boolean a(int paramInt, int[] paramArrayOfInt)
  {
    int i6 = m.b;
    boolean bool = m.a;
    int i1 = 0;
    if (i1 < this.j) {}
    do
    {
      this.f[i1] = 2147483647;
      i1++;
      if (i6 != 0) {
        break label63;
      }
      if (bool) {
        break label62;
      }
      if (!bool) {
        break;
      }
      this.f[paramInt] = 0;
    } while (i6 != 0);
    paramArrayOfInt[paramInt] = 1;
    label62:
    label63:
    int i5 = 0;
    if (i5 <= this.a.k() - 1) {}
    d locald;
    int i2;
    int i3;
    int i4;
    label230:
    while (i6 != 0)
    {
      if (bool) {
        break label337;
      }
      a.c.m localm2 = this.a.w();
      do
      {
        do
        {
          if (!localm2.e()) {
            break label312;
          }
          locald = localm2.a();
          i2 = locald.d();
          i3 = locald.e().f();
          i4 = locald.f().f();
          if (bool) {
            break;
          }
          if (this.h[i2] < this.c[i2])
          {
            if (i6 != 0) {
              break label230;
            }
            if (this.f[i3] != 2147483647)
            {
              i1 = this.f[i3] + this.d[i2];
              if (i6 != 0) {
                break label230;
              }
              if (this.f[i4] > i1)
              {
                this.f[i4] = i1;
                paramArrayOfInt[i4] = 1;
              }
            }
          }
          if (i6 == 0)
          {
            if (this.h[i2] > 0)
            {
              if (i6 != 0) {
                continue;
              }
              if (this.f[i4] != 2147483647)
              {
                i1 = this.f[i4] - this.d[i2];
                if (i6 != 0) {
                  continue;
                }
                if (this.f[i3] > i1)
                {
                  this.f[i3] = i1;
                  paramArrayOfInt[i3] = 1;
                }
              }
            }
            localm2.f();
          }
        } while (!bool);
        i5++;
      } while (i6 != 0);
      if (!bool) {
        break;
      }
    }
    label312:
    label337:
    a.c.m localm1 = this.a.w();
    label480:
    do
    {
      if (!localm1.e()) {
        break;
      }
      locald = localm1.a();
      i2 = locald.d();
      i3 = locald.e().f();
      i4 = locald.f().f();
      if ((i6 == 0) && (bool)) {
        break label543;
      }
      if (i6 == 0)
      {
        if (this.f[i3] != 2147483647)
        {
          if (i6 != 0) {
            break label480;
          }
          if (this.h[i2] < this.c[i2])
          {
            if (i6 != 0) {
              break label480;
            }
            if (this.f[i4] > this.f[i3] + this.d[i2]) {
              return false;
            }
          }
        }
        if (i6 != 0) {
          continue;
        }
      }
      if (this.f[i4] != 2147483647)
      {
        if (i6 != 0) {
          continue;
        }
        if (this.h[i2] > 0)
        {
          if (i6 != 0) {
            continue;
          }
          if (this.f[i3] > this.f[i4] - this.d[i2]) {
            return false;
          }
        }
      }
      localm1.f();
    } while (!bool);
    label543:
    return true;
  }
  
  private static class a_
  {
    private String a;
    private mb b = new mb();
    int c;
    int d;
    int e;
    
    public void a()
    {
      this.c = 0;
      this.d = 0;
      this.e = 0;
      this.a = "0";
      this.b.a();
      this.b.g();
    }
    
    public void c()
    {
      this.a = this.b.toString();
    }
    
    public String toString()
    {
      return "\nMinCostFlow-Statistics:\n   Time: " + this.a + "\n   Scalings: " + this.c + "\n   Augmentations : " + this.d + "\n   ExtractMins: " + this.e;
    }
  }
}



/* Location:           E:\idea\

 * Qualified Name:     a.a.o

 * JD-Core Version:    0.7.0.1

 */